package edu.ucsc.mit2008.swan.editor.coreUI.internal.presentation.wizard;

import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem;

import edu.ucsc.mit2008.swan.editor.core.presentation.SwanPresentationFactory;
import edu.ucsc.mit2008.swan.editor.core.presentation.model.IModelChangedListener;
import edu.ucsc.mit2008.swan.editor.core.presentation.model.ISwanPresentation;
import edu.ucsc.mit2008.swan.editor.coreUI.SwanCoreUIPlugin;
import edu.ucsc.mit2008.swan.editor.coreUI.internal.presentation.wizard.page.NewPresentationWizardFirstPage;

public class NewPresentationWizard extends Wizard implements IWizard{

	private NewPresentationWizardFirstPage newPresentationWizardFirstPage;
	
	private ISwanPresentation currentModel;
	
	public NewPresentationWizard() {
		super();
		IDialogSettings favoritesSettings = SwanCoreUIPlugin.getDefault().getDialogSettings();
		IDialogSettings wizardSettings = favoritesSettings.getSection(getWizardID());
		if (wizardSettings == null)
			wizardSettings = favoritesSettings.addNewSection(getWizardID());
		setDialogSettings(favoritesSettings);
		setNeedsProgressMonitor(true);
		currentModel = SwanPresentationFactory.getInstance().createPresentaton();
	}

	@Override
	public boolean performFinish() {
		return true;
	}
	
	@Override
	public void addPages() {
		newPresentationWizardFirstPage = new NewPresentationWizardFirstPage();
		newPresentationWizardFirstPage.setModel(currentModel);
		addPage(newPresentationWizardFirstPage);
		installListener();
	}
	
	protected String getWizardID(){
		return "NewPresentationWizard";
	}
	
	private void installListener(){
		newPresentationWizardFirstPage.addModelChangedListener(new PresentationChangedListener());
	}
	
	private class PresentationChangedListener implements  IModelChangedListener{

		@Override
		public void modelChanged(ISwanPresentation change) {
			newPresentationWizardFirstPage.setModel(change);
			getContainer().updateButtons();
		}
		
	}
}
